<?php

namespace common\models\base;

use Yii;

/**
 * This is the model class for table "{{%bank}}".
 *
 * @property int $id
 * @property string $sign_code
 * @property string $headquarters 总部
 * @property string $name
 * @property string $api_base_url 基本URL
 * @property string $phybrno 业务受理网点 //todo 读取订单银行对应编号
 * @property int $status
 * @property string $contact_mobile 联系人手机号
 *
 * @property BankGuaranteeCompanyBind[] $bankGuaranteeCompanyBinds
 * @property GuaranteeCompany[] $guaranteeCompanies
 * @property CreditOrder[] $creditOrders
 */
class Bank extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%bank}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['sign_code', 'headquarters', 'name'], 'required'],
            [['status'], 'integer'],
            [['sign_code'], 'string', 'max' => 32],
            [['headquarters', 'name', 'api_base_url'], 'string', 'max' => 50],
            [['phybrno'], 'string', 'max' => 8],
            [['contact_mobile'], 'string', 'max' => 11],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'sign_code' => Yii::t('app', 'Sign Code'),
            'headquarters' => Yii::t('app', '总部'),
            'name' => Yii::t('app', 'Name'),
            'api_base_url' => Yii::t('app', '基本URL'),
            'phybrno' => Yii::t('app', '业务受理网点 //todo 读取订单银行对应编号'),
            'status' => Yii::t('app', 'Status'),
            'contact_mobile' => Yii::t('app', '联系人手机号'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getBankGuaranteeCompanyBinds()
    {
        return $this->hasMany(BankGuaranteeCompanyBind::className(), ['bank_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getGuaranteeCompanies()
    {
        return $this->hasMany(GuaranteeCompany::className(), ['id' => 'guarantee_company_id'])->viaTable('{{%bank_guarantee_company_bind}}', ['bank_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCreditOrders()
    {
        return $this->hasMany(CreditOrder::className(), ['bank_id' => 'id']);
    }
}
